package com.briup.day04;

import java.util.InputMismatchException;
import java.util.Scanner;


/**
 * @author 谭梦寻
 * @version 1.1
 * 请编写⼀个Java程序，实现从键盘中输⼊年份 ⽉份 ⽇期，
 * 输出这⼀天是该年的第⼏天
 */
public class Test06 {
//    获取当前月份之前的天数 如 5月之前有121天
    public static int getDays(int mouth) {
        switch (mouth) {
            case 1:
                mouth = 0;
                break;
            case 2:
                mouth = 31;
                break;
            case 3:
                mouth = 60;
                break;
            case 4:
                mouth = 91;
                break;
            case 5:
                mouth = 121;
                break;
            case 6:
                mouth = 152;
                break;
            case 7:
                mouth = 182;
                break;
            case 8:
                mouth = 213;
                break;
            case 9:
                mouth = 244;
                break;
            case 10:
                mouth = 274;
                break;
            case 11:
                mouth = 305;
                break;
            case 12:
                mouth = 335;
                break;
        }
        return mouth;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String date = "";
        int year = 0;
        int mouth, mouths = 0;
        int day = 0;
        int days = 0;
        try {
            System.out.println("请输入日期：");
//            nextLine() 捕获键盘输入的包括空格等符号
            date = sc.nextLine();
            String s = date.substring(0, 4);
            year = Integer.parseInt(s);
            String m = date.substring(5, 7);
            mouth = Integer.valueOf(m);
            String d = date.substring(8, 10);
            day = Integer.valueOf(d);
//            判断平年闰年 如果是闰年
            if ((year % 4 == 0 && year % 100 == 0 && year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
                days = getDays(mouth) + day;


            } else {
                //                三月之后 平年比闰年少一天
                if (mouth > 3) {
                    days = getDays(mouth) -1 + day;
                }
            }
            System.out.println(days);

        } catch (InputMismatchException e) {
            System.out.println("输入的不是数字");
        }
//        System.out.println(date);
    }
}
